﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataAccessLogic;
using System.Data;

namespace BusinessLogic
{
    [Serializable]
    public class Country : FormattedCodeTable<Country>
    {
        #region Methods
        public Country() { }        

        public override void Create()
        {
            this._id = CountryDataAccess.Create(this);
        }

        public override void Delete()
        {
            CountryDataAccess.Delete(this);
        }

        protected override List<Country> ProtectedGetAll()
        {
            DataTable dt = CountryDataAccess.GetAll();

            List<Country> countries = null;

            if ((dt != null) && (0 < dt.Rows.Count))
            {
                countries = new List<Country>();

                foreach (DataRow row in dt.Rows)
                {
                    countries.Add(CountryDataAccess.BindDataToCountry(row));
                }
            }

            return countries;
        }

        protected override Country ProtectedGetByID(Guid id)
        {
            DataRow row = CountryDataAccess.GetByID(id);

            if (row != null)
            {
                return CountryDataAccess.BindDataToCountry(row);
            }

            return null;
        }
        
        public override void Update()
        {
            throw new NotImplementedException();
        }
        #endregion


        #region Properties
        public override string CacheKeyName
        {
            get
            {
                return SEPDefaults.CacheKeyNames.COUNTRIES;
            }
        }
        #endregion
    }
}